package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xwl
 * Date: 2023-06-13
 * Time: 14:23
 */

class MyThread extends Thread {
    @Override
    public void run() {
        // 入口方法 -- 重写了父类的方法,会被java自动执行到
        while (true) {
            System.out.println("hello world");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class ThreadDemo1 {
    public static void main(String[] args) {
        // 创建MyThread实例
        Thread t = new MyThread();
        // 启动实例,创建新线程
        t.start();
//      // run是在main线程中执行,不会创建新的线程
//        t.run();
        // main线程打印
        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
